Conversation
|
QHelp previews: csharp/ql/src/Security Features/CWE-451/MissingXFrameOptions.qhelpMissing clickjacking protectionWeb sites that do not restrict framing using the RecommendationSet the For ASP.NET Framework applications, the header may be specified either in the For ASP.NET Core applications, set the header on ExampleThe following example shows how to specify the This next example shows how to specify the protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("X-Frame-Options", "DENY");
}The following ASP.NET Core example uses an enforced Content Security Policy to disallow framing: void Configure(IApplicationBuilder app)
{
app.Use(async (context, next) =>
{
context.Response.Headers["Content-Security-Policy"] = "frame-ancestors 'none'";
await next();
});
}References
|
Summary
The
cs/web/missing-x-frame-optionsquery was primarily modeled around legacy ASP.NET Framework applications hosted by IIS. As a result, it could report false positives for ASP.NET Core applications that correctly configure clickjacking-related response headers in code.This change:
X-Frame-Optionswritten through ASP.NET CoreHttpResponse.HeadersContent-Security-Policyheaders containing aframe-ancestorsdirectiveAppend,Add, andTryAddLegacy ASP.NET Framework and
Web.confighandling remains supported.Testing
Web.configtests for CSPframe-ancestorshandling.